package com.itheima.Repository;
import com.itheima.domain.User;
import org.apache.ibatis.annotations.Delete;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
import java.util.List;
public interface UserRepository extends JpaRepository<User,Integer>, JpaSpecificationExecutor<User> {
    /**
     * 注意不需要增加 save(T)
     */
    @Transactional
    @Modifying
    @Query("update t_user set id=?1,username=?2,password=?3,birthday=?4 where id=?1")
    public void update(Integer id, String username, String password, Date birthday);

    @Transactional
    @Modifying
    @Query("delete from t_user where id=?1")
    public void delete(Integer id);

    /**
     * 根据id查询用户信息
     * @param id
     * @return
     */
    @Query(nativeQuery = true,value = "select * from t_user where id=?1")
    public User findOne(Integer id);

    /**
     * 批量删除用户
     *
    @Transactional
    @Modifying
    @Delete("<script>"  +
            "delete from t_user where id in " +
            "<foreach collection='list' item='id' open='(' separator=',' close=')'> " +
            "#{id}" +
            "</foreach>" +
            "</script>")
    public void delAllUser(List<Integer> delList);
     */
}
